package cn.edu.cdtu.yulei.test_demo.controller;

import cn.edu.cdtu.yulei.test_demo.model.InterfaceInfo;
import cn.edu.cdtu.yulei.test_demo.service.impl.InterfaceInfoImpl;
import com.google.gson.Gson;

import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/uriViews.do")
public class InterfaceInfoController extends HttpServlet {

    /**
     * 获取接口信息
     * @param req
     * @param resp
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        InterfaceInfoImpl interfaceInfo = new InterfaceInfoImpl();
        List<InterfaceInfo> interfaceInfos = interfaceInfo.getInterfaceInfo();
        interfaceInfo.addInterfaceInfo("/commService/uriViews.do");
        ServletOutputStream outputStream = resp.getOutputStream();
        //使用Gson进行格式化json
        Gson gson = new Gson();
        outputStream.write(gson.toJson(interfaceInfos).getBytes("utf-8"));
        outputStream.close();
    }
}
